package com.boot.domain;

import java.io.Serializable;

/**
 * @author songlin.an
 * @className ServiceResponse
 * @description TODO
 * @date 2023/5/5 16:17
 **/
public class ServiceResponse<T> implements Serializable {

    private static final long serialVersionUID = -8214802966636823545L;

    private String code;

    private String msg;

    /**
     * 业务结果数据
     */
    private T result;



    public static <T> ServiceResponse<T> success() {
        ServiceResponse<T> response = new ServiceResponse<T>();
        return response;
    }

    /**
     * 返回特定类型的失败呼应
     *
     * @return
     */
    public static <T> ServiceResponse failureResponse(String code, String msg) {
        ServiceResponse<T> response = new ServiceResponse<>();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
    public static <T> ServiceResponse failureResponse(String code, T t) {
        ServiceResponse<T> response = new ServiceResponse<>();
        response.setCode(code);
        response.setResult(t);
        return response;
    }



    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }
}
